<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="text" name="" id="num">
    <button id="btn">计算阶乘</button>
    <div id="output"></div>
</body>
<script>
    /*
        计算任意数的阶乘n! 1*2*3*4*5...*n
        n!=1*2*3*4*5...*n
        5!=5*4*3*2*1
    */

    var num = document.getElementById('num');
    var btn = document.getElementById('btn');
    var output = document.getElementById('output');

    btn.onclick = function() {
        //计算阶乘
        var result = num.value;//获取表单的值
        var sum = 1;//存放累乘的结果
        for(var i = result; i >= 1; i--) {
            sum *= i;
        }
        //渲染结果
        output.innerHTML = sum;
    }
</script>
</html>